package virtualstock.stockgraph;

import java.applet.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.*;

import graph.*;


public class DisplayStockGraph extends Applet
{
	//private int stockID = Integer.parseInt((String) this.getParameter("sid"));
	int stockID =3;
    Graph2D graph1;
    Graph2D graph2;
    Graph2D graph3;
    DataSet data1;
    DataSet data2;
    DataSet data3;
    Axis xaxis;
    Axis yaxis_left;
    Axis yaxis_right;
    double d1[], d2[], d3[];
    int np = 100000;
    //long stockID;
    
	public void init()
    {

	int i, j;
	final int DAY= 30;
	final int MONTH = 12;
	double d1[] = new double[DAY*2];
	double d2[] = new double[MONTH*2];
	double x, y;

	graph1 = new Graph2D();
	graph1.drawzero = false;
	graph1.drawgrid = false;
	graph1.borderTop = 50;
	graph1.borderRight = 100;

	graph2 = new Graph2D();
    graph2.drawzero = false;
    graph2.drawgrid = false;
    graph2.borderTop = 50;
    graph2.borderRight=100;



	setLayout(new GridLayout(1,2));

	add(graph1);
	add(graph2);

	int d1len = 0;
	int d2len = 0;
	
	int k = 1;
	for(i = 0; i < DAY; i++)
	{
	    x = i + 1;
	    
		Date date = new Date(2009, 9, k);

		GetStockPrice gsp= new GetStockPrice(stockID, date);
	//	System.out.println("day is: " + date.getDay());

	    y = GetStockPrice.getStockPrice();
	    if (y == 0)
	    {
	    	i--;
	    	k++;
	    	continue;
	    }
	    d1[i*2] = x;
	    d1[i*2+1] = y;
	   // System.out.println("Month: For input " + x + ", the price is " + y);	
	    k++;
	}
	    d1len = i;

	for(i = 0; i < MONTH; i++)
	{	  
		x = i + 1;

		k = 1;
		while(true)
		{
			Date date = new Date(2009, i, k);

			GetStockPrice gsp= new GetStockPrice(stockID, date);

		    y = GetStockPrice.getStockPrice();
		    if(y != 0)
		    	break;
		    else
		    	k++;
		}
		
	    d2[i*2] = x;
	    d2[i*2 + 1] = y;
	   // System.out.println("Year: For input " + x + ", the price is " + y);
	}
	
	    d2len = i;

	
        data1 = graph1.loadDataSet(d1, d1len);
        data1.linestyle = 1;
        data1.linecolor   =  new Color(255,0,0);
        data1.marker    = 1;
        data1.markerscale = 1;
        data1.markercolor = new Color(0,0,255);
        data1.legend(200,100,"Month History");
        data1.legendColor(Color.black);
        
        data2 = graph2.loadDataSet(d2,d2len);
        data2.linestyle = 1;
        data2.linecolor   =  new Color(255,0,0);
        data2.marker    = 1;
        data2.markerscale = 1;
        data2.markercolor = new Color(0,0,255);
        data2.legend(200,120,"Year History");
        data2.legendColor(Color.black);

        xaxis = graph1.createAxis(Axis.BOTTOM);
        xaxis.attachDataSet(data1);
        xaxis.setTitleText("Day");
        xaxis.setTitleFont(new Font("TimesRoman",Font.PLAIN,25));
        xaxis.setLabelFont(new Font("Helvetica",Font.PLAIN,20));
        xaxis.setTitleColor(new Color(0,0,255));

        yaxis_left = graph1.createAxis(Axis.LEFT);
        yaxis_left.attachDataSet(data1);
        yaxis_left.setTitleText("$ Price ");
        yaxis_left.setTitleFont(new Font("TimesRoman",Font.PLAIN,25));
        yaxis_left.setLabelFont(new Font("Helvetica",Font.PLAIN,20));
        yaxis_left.setTitleColor( new Color(0,0,255) );
      	

        xaxis = graph2.createAxis(Axis.BOTTOM);
        xaxis.attachDataSet(data2);
        xaxis.setTitleText("Month");
        xaxis.setTitleFont(new Font("TimesRoman",Font.PLAIN,25));
        xaxis.setLabelFont(new Font("Helvetica",Font.PLAIN,20));
        xaxis.setTitleColor(new Color(0,0,255));

        yaxis_left = graph2.createAxis(Axis.LEFT);
        yaxis_left.attachDataSet(data2);
        yaxis_left.setTitleText("$ Price ");
        yaxis_left.setTitleFont(new Font("TimesRoman",Font.PLAIN,25));
        yaxis_left.setLabelFont(new Font("Helvetica",Font.PLAIN,20));
        yaxis_left.setTitleColor( new Color(0,0,255) );
    


    }

}
